import { apiUrl } from "@api/index";
import type {ExDatasetAnnotation, DatasetAnnotation, ListDatasetAnnotationsParam, CreateDatasetAnnotationParam, UpdateDatasetAnnotationParam, DeleteDatasetAnnotationParam} from "@store/entity/dataset/annotation";
import { get, post, put, del, ToUrlSearchParams, type Paged } from "@util/http";

export const listPagedDatasetAnnotationsBuild = (datasetCode: string) => {
  return async (val: ListDatasetAnnotationsParam): Promise<Paged<ExDatasetAnnotation>> => {
    return await get<Paged<ExDatasetAnnotation>>(apiUrl(`/dataset/${datasetCode}/annotation`), ToUrlSearchParams(val), { auth: true });
  };
};

export const buildGetDatasetAnnotationBuild = (datasetCode: string) => {
  return async (id: number): Promise<DatasetAnnotation> => {
    return await get<DatasetAnnotation>(apiUrl(`/dataset/${datasetCode}/annotation/${id}`));
  }
};

export const createDatasetAnnotationBuild = (datasetCode: string) => {
  return async (val: CreateDatasetAnnotationParam): Promise<DatasetAnnotation> => {
    return await post<DatasetAnnotation>(apiUrl(`/dataset/${datasetCode}/annotation`), val);
  }
};

export const updateDatasetAnnotationBuild = (datasetCode: string) => {
  return async (val: UpdateDatasetAnnotationParam): Promise<DatasetAnnotation> => {
    return await put<DatasetAnnotation>(apiUrl(`/dataset/${datasetCode}/annotation/${val.id}`), val);
  }
};

export const deleteDatasetAnnotationBuild = (datasetCode: string) => {
  return async (val: DeleteDatasetAnnotationParam): Promise<DatasetAnnotation> => {
    return await del<DatasetAnnotation>(apiUrl(`/dataset/${datasetCode}/annotation/${val.id}`));
  }
};